package logic

import (
	"context"
	"fmt"
	"rpc/model/redis"

	"rpc/internal/svc"
	"rpc/pb/cart"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartItemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartItemLogic {
	return &CartItemLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartItemLogic) CartItem(in *cart.CartItemRequest) (*cart.CartItemResponse, error) {
	// todo: add your logic here and delete this line
	item, err := redis.CartItem(in.UserId)
	if err != nil {
		logx.Error("列表展示失败")
		return nil, fmt.Errorf("列表展示失败")
	}

	return &cart.CartItemResponse{Item: item}, nil
}
